package com.softserveinc.cheatsheet.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.springframework.security.core.GrantedAuthority;

@Entity
@NamedQueries({
		@NamedQuery(name = UserAuthority.GET_AUTHORITY_BY_NAME_QUERY, query = "from UserAuthority where authorityName = :name"),
		@NamedQuery(name = UserAuthority.LIST_AUTHORITY_BY_NAME_QUERY, query = "from UserAuthority order by authorityName") })
public class UserAuthority implements Serializable, GrantedAuthority {

	public static final String GET_AUTHORITY_BY_NAME_QUERY = "getUserAuthorityByName";
	public static final String LIST_AUTHORITY_BY_NAME_QUERY = "listUserAuthorityByName";

	public static final String ROLE_ANONYMOUS = "ROLE_ANONYMOUS";
	public static final String ROLE_USER = "ROLE_USER";

	private static final long serialVersionUID = 1L;

	@Column(nullable = false, unique = true)
	private String authorityName;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	public UserAuthority() {
	}

	public UserAuthority(String authorityName) {
		super();
		setAuthorityName(authorityName);
	}

	@Override
	public String getAuthority() {
		return authorityName;
	}

	public String getAuthorityName() {
		return authorityName;
	}

	public Long getId() {
		return id;
	}

	public void setAuthorityName(String authorityName) {
		this.authorityName = authorityName;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Override
	public String toString() {
		return "UserAuthority [authorityName=" + authorityName + ", id=" + id
				+ "]";
	}

}
